import { ProForm, ProFormText } from '@ant-design/pro-components';
import { useRef } from 'react';
/**
 *
 * @param props 提示词节点
 * @returns
 */
const LLMNode: React.ComponentType<NodeSetting.Setting<NodeSetting.LLMNode>> = (props) => {
  const formRef = useRef();
  const onFormFinish = (formData: Record<string, any>) => {
    const param: NodeSetting.LLMNode = formData as NodeSetting.LLMNode
    props?.updateSetting!({ modelAddress: param.modelAddress, apiKey: param.apiKey })
    props.messageTip('暂存成功', 'success')
  }
  // 自动存放值
  const onChange = async () => {
    const values = await ((formRef.current) as any).getFieldsValue();
    const param: NodeSetting.LLMNode = values as NodeSetting.LLMNode
    props?.updateSetting!({ modelAddress: param.modelAddress, apiKey: param.apiKey })
  }
  return (<div>
    <ProForm
      formRef={formRef}
      onFinish={async (formData) => onFormFinish(formData)}
      onChange={onChange}
      initialValues={props.setting}
    >
      <ProFormText name="modelAddress" label="模型地址" />
      <ProFormText name="apiKey" label="api key" />
    </ProForm>
  </div>)
}
export default LLMNode;
